<template>
  <view class="qrcode">
    <u--image
        v-if="qrcode"
        @click="previewImage"
        width="100%"
        height="100%"
        mode="widthFix"
        lazy-load :fade="true" duration="450" :src="qrcode"></u--image>
  </view>
</template>

<script>
// import color from '@/config/color.js'
import config from '../../config/config'
import base64 from '../../util/base64'
import User from '../../api/user'
const userModel = new User()

export default {
  data() {
    return {
      baseUrl: config.baseUrl,
      text: '',
      qrcode: ''
    }
  },
  onLoad() {
    this.fetch()
  },
  methods: {
    fetch() {
      // 生成
      // const code = '/sub_service/qrcode/save_referrer?id='
      const code = '/app.apk'
      const domain = config.baseUrl
      // 转向到H5的地址前缀
      userModel.qrcodeListApp({ code, domain }).then(response => {
        let { data } = response
        data = base64.parse(data)
        console.log(data)
        // this.qrcode = data.qrcode + `?${new Date().getTime()}`
        this.qrcode = data.list[0] + `?${new Date().getTime()}`
        // console.log(this.qrcode)
        this.text = data.text
      })
    },
    previewImage() {
      uni.previewImage({
        urls: [this.qrcode],
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  height: 10100px;
  background: black;
  margin-top: 10px;
}
</style>
